package com.jason.www.service.impl;

import com.googlecode.ehcache.annotations.Cacheable;
import com.jason.www.dao.UserMapper;
import com.jason.www.dao.UserRolesMapper;
import com.jason.www.domain.Roles;
import com.jason.www.domain.User;
import com.jason.www.domain.UserRoles;
import com.jason.www.service.UserService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Set;

/**
 * Created by Cai on 2018/6/7.
 */
@Service
@Transactional
public class UserServiceImpl implements UserService {
    private Logger logger = Logger.getLogger(this.getClass());

    @Autowired
    private UserMapper userMapper;
    @Autowired
    private UserRolesMapper userRolesMapper;

    @Override
    @Cacheable(cacheName="userCache")
    public List<User> findUser() {
        logger.info("findUser 方法执行");
        System.out.println("service方法执行 未进行缓存");
        return userMapper.getAllUser();
    }

    @Override
    public Boolean addUser(User user) {
        int result = userMapper.insert(user);
        int i = 1/0;
        return result == 1? true : false;
    }

    @Override
    public Set<Roles> getRolesByLoginName(String loginName) {
        return userMapper.getRolesByLoginName( loginName);
    }

    @Override
    public User getUserByUsername(String username) {
        return userMapper.getUserByUsername(username);
    }

    @Override
    public User getUserByLoginName(String loginName) {
        return userMapper.getUserByLoginName(loginName);
    }

}
